import { escloudHttp, downloadHttp } from '@/utils/http/axios';
import { UploadInfo, RenameFileInfo } from './modal/uploadModel';
import { ErrorMessageMode } from '#/axios';
import { ContentTypeEnum } from '@/enums/httpEnum';

enum Api {
  uploadApi = '/eslogis-tps/userFiles/upload',
  renameFileApi = '/eslogis-tps/userFiles/rename/',
  delFileApi = '/eslogis-tps/userFiles/deleteById/',
  downloadFileApi = '/eslogis-tps/userFiles/down/',
  exportExcel = '/eslogis-tps/userFiles/download?url=',
  downloadBatch = '/eslogis-tps/archiveFiles/downloadBatch',
}

/**
 * @description: 上传接口
 */
export function uploadApi(params, mode: ErrorMessageMode = 'modal') {
  return escloudHttp.post<UploadInfo>(
    {
      url: Api.uploadApi,
      headers: {
        'Content-Type': ContentTypeEnum.FORM_DATA,
      },
      params,
    },
    { errorMessageMode: mode },
  );
}

/**
 * @description: 重命名
 */
export function renameFileApi(params, mode: ErrorMessageMode = 'modal') {
  return escloudHttp.put<RenameFileInfo>(
    {
      url: `${Api.renameFileApi}${params.id}?name=${params.name}`,
    },
    { errorMessageMode: mode },
  );
}

/**
 * @description: 删除
 */
export function delFileApi(id, mode: ErrorMessageMode = 'modal') {
  return escloudHttp.delete<RenameFileInfo>(
    {
      url: Api.delFileApi + id,
    },
    { errorMessageMode: mode },
  );
}

/**
 * @description: 下载
 */
export function downloadFileApi(url, mode: ErrorMessageMode = 'modal') {
  return downloadHttp.post<any>(
    {
      url: Api.exportExcel + url,
    },
    { errorMessageMode: mode },
  );
}

/**
 * @description: 下载文件夹
 */
export function downloadBatch(params, mode: ErrorMessageMode = 'modal') {
  return downloadHttp.post<any>(
    {
      url: Api.downloadBatch,
      params,
    },
    { errorMessageMode: mode },
  );
}
